<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <search ref='search' :config='searchConfig' @search='search' @getHeight='getHeight' />
    <!-- table区域-begin -->
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        :border='true'
        :resizable='true'
        :showOverflow='true'
        size='mini'
        :loading='loading'
        :height='pageHeight-seachHeight-90'
        :align='left'
        :columns='columns'
        :data='dataSource'
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        :toolbar-config='tableToolbar'
        :checkbox-config="checkboxConfig"
        v-bind='vexConfig'
        @checkbox-change='selectChangeEvent'
        @checkbox-all='selectChangeEvent'
      >
        <template #toolbar_buttons>
          <div class='table-operator'>
            <a-dropdown v-if="selectedRowKeys.length > 0">
              <a-menu slot="overlay">
                <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
              </a-menu>
<!--              <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
            </a-dropdown>
            <a-button type="primary"  @click="downExportXls('sfaVisitTakeStock_service')">导出</a-button>

          </div>
        </template>
        <template #detail='{ row,rowIndex }'>
          <a @click='handleDetail(row)'>{{ row.visitId }}</a>
        </template>

        <template #status='{ row }'>
          <a-switch :checked='row.status' size='small' @change='handleStatus(row,$event)' />
        </template>
        <template #pager>
          <vxe-pager
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :currentPage.sync='ipagination.current'
            :page-size.sync='ipagination.pageSize'
            :total='ipagination.total'
            :pageSizes='ipagination.pageSizeOptions'
            @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <inventory-details ref='modalForm'></inventory-details>
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import {postAction} from "@api/manage"
  import {PageListMixin} from '@/mixins/PageListMixin'
  import JDate from '@comp/cn-form/JDate'
  import InventoryDetails from './modules/InventoryDetails'

  export default {
    name: "SfaVisitTakestockList",
    mixins: [PageListMixin],
    components: {
      JDate,
      InventoryDetails
    },
    data() {
      return {
        description: '库存明细报表',
        //查询区域
        searchConfig:[
          // {
          //   type: 'input',
          //   name: 'createName',
          //   placeholder: '人员姓名'
          // },
          // {
          //   type: 'input',
          //   name: 'positionName',
          //   placeholder: '职位名称'
          // },
          {
            type: 'input',
            name: 'clientCode',
            placeholder: '经销商编码'
          },
          {
            type: 'input',
            name: 'clientName',
            placeholder: '经销商名称',
          },
          {
            type: 'date-range', //范围选择
            range: ['startTime', 'endTime'],
            name: 'range',
            format: 'YYYY-MM-DD',
            placeholder: ['开始时间', '结束时间']
          }
        ],
        // 表头
        columns:[
          { type: 'checkbox', width: 50, fixed: 'left' },
          // {
          //   title: '线路编号',
          //   minWidth:80,
          //   field: 'visitId',
          //   slots: { default: 'detail' }
          // },
          {
            title: '经销商编码',
            minWidth:80,
            field: 'clientCode'
          },
          {
            title: '经销商名称',
            minWidth:80,
            field: 'clientName'
          },
          {
            title: '商品编码',
            minWidth:80,
            field: 'productCode'
          },
          {
            title: '商品名称',
            minWidth:80,
            field: 'productName'
          },
          {
            title: '单位',
            minWidth:80,
            field: 'basicUnitStr'
          },
          {
            title: '库存数量',
            minWidth:80,
            field: 'nowNum'
          },
          {
            title: '创建人',
            minWidth:80,
            field: 'createName'
          },
          {
            title: '创建时间',
            minWidth:80,
            field: 'createTime'
          },
        ],
        isorter: {
          permflag: 'repertory_info_list'
        },
        url: {
          list: window._CONFIG['domianSfaURL'] + "/visit/sfaVisitTakestockController/findPageList",
          detail: window._CONFIG['domianSfaURL'] + '/visit/sfaSmallVisitTakestockController/getInfo',
          // delete: "/visit/sfaVisitTakestockEntity/delete",
          // deleteBatch: "/visit/sfaVisitTakestockEntity/deleteBatch",
          exportXlsUrl: window._CONFIG['domianSfaURL'] + "visit/sfaVisitTakestockController/exportXls",
          // importExcelUrl: "visit/sfaVisitTakestockEntity/importExcel",
        },
      }
    },
    computed: {
      importExcelUrl: function () {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      //详情
      handleDetail(e){
        let params ={}
        params.type = 1
        params.visitDate = e.createDate
        params.visitId = e.visitId
        postAction(this.url.detail, params).then(async (res) => {
          if (res.success) {
            // this.$message.success(res.message)
            await this.loadData()
            this.$refs.modalForm.edit(res.success)
            this.$refs.modalForm.title = '详情'
            this.$refs.modalForm.disableSubmit = true
          } else {
            this.$message.warning(res.message)
          }
        }).finally(() => {
          // this.$refs.ConfigPosCust.confirmLoading = false
          //that.close();
        })

      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>